﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MongoDB.Bson.Serialization;
using MonsterEngine.Abilities;
using MonsterEngine.Augments;

namespace MonsterEngine.Entities
{
    /// <summary>
    /// This only exists because Mongo does not properly cast objects into derived types
    /// This mapping needs to be done any time an interface object is used/created
    /// </summary>
    public class RegisterDerived
    {
        public static void All()
        {
            RegisterEntities();
            RegisterAbilities();
            RegisterAugments();
        }

        public static void RegisterEntities()
        {
            if (!BsonClassMap.IsClassMapRegistered(typeof(Account)))
            {
                BsonClassMap.RegisterClassMap<Account>();
            }

            if (!BsonClassMap.IsClassMapRegistered(typeof(Character)))
            {
                BsonClassMap.RegisterClassMap<Character>();
            }
        }

        public static void RegisterAbilities()
        {
            if (!BsonClassMap.IsClassMapRegistered(typeof(DamagePlus)))
            {
                BsonClassMap.RegisterClassMap<DamagePlus>();
            }
            if (!BsonClassMap.IsClassMapRegistered(typeof(Heal)))
            {
                BsonClassMap.RegisterClassMap<Heal>();
            }
            if (!BsonClassMap.IsClassMapRegistered(typeof(HealthSteal)))
            {
                BsonClassMap.RegisterClassMap<HealthSteal>();
            }
            if (!BsonClassMap.IsClassMapRegistered(typeof(LifeDrip)))
            {
                BsonClassMap.RegisterClassMap<LifeDrip>();
            }
            if (!BsonClassMap.IsClassMapRegistered(typeof(Sleep)))
            {
                BsonClassMap.RegisterClassMap<Sleep>();
            }
        }

        public static void RegisterAugments()
        {
            if (!BsonClassMap.IsClassMapRegistered(typeof(HealOverTime)))
            {
                BsonClassMap.RegisterClassMap<HealOverTime>();
            }
            if (!BsonClassMap.IsClassMapRegistered(typeof(MissTurn)))
            {
                BsonClassMap.RegisterClassMap<MissTurn>();
            }
        }
    }
}
